﻿//-----------------------------------------------------------------------
// <copyright file="SqlErrorInsertUnitTest.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics
{
    using System;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;

    using Microsoft.Data.Schema.UnitTesting;
    using Microsoft.Data.Schema.UnitTesting.Conditions;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Provides database unit tests for [dbo].[usp_SqlLogInsert] stored procedure and associated [dbo].[SqlLog] table.
    /// </summary>
    [TestClass]
    public class SqlLogInsertUnitTest : DatabaseTestClass
    {
        #region SqlLogInsertUnitTest Private Fields

        private DatabaseTestActions SqlLogInsertStoredProcedureUnitTestData; 
        
        #endregion

        #region public SqlLogInsertUnitTest()

        /// <summary>
        /// Initializes a new instance of the <see cref="T:SqlLogInsertUnitTest"/> class.
        /// </summary>
        public SqlLogInsertUnitTest()
        {
            InitializeComponent();
        }

        #endregion

        #region public void TestInitialize()

        /// <summary>
        /// Performs test initialization.
        /// </summary>
        [TestInitialize]
        public void TestInitialize()
        {
            base.InitializeTest();
        } 

        #endregion

        #region public void TestCleanup()

        /// <summary>
        /// Performs test cleanup.
        /// </summary>
        [TestCleanup]
        public void TestCleanup()
        {
            base.CleanupTest();
        } 

        #endregion

        #region public void SqlLogInsertStoredProcedureUnitTest()

        /// <summary>
        /// Provides unit testing for the [dbo].[usp_SqlLogInsert] stored procedure and associated [dbo].[SqlLog] table.
        /// </summary>
        [TestMethod]
        [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "testResults")]
        [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "pretestResults")]
        [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "posttestResults")]
        public void SqlLogInsertStoredProcedureUnitTest()
        {
            DatabaseTestActions actions = this.SqlLogInsertStoredProcedureUnitTestData;
            
            // execute the pre-test script
            Trace.WriteLineIf((actions.PretestAction != null), "Executing pre-test script...");
            ExecutionResult[] pretestResults = TestService.Execute(this.PrivilegedContext, this.PrivilegedContext, actions.PretestAction);
            
            // execute the test script
            Trace.WriteLineIf((actions.TestAction != null), "Executing test script...");
            ExecutionResult[] testResults = TestService.Execute(this.ExecutionContext, this.PrivilegedContext, actions.TestAction);
            // execute the post-test script

            Trace.WriteLineIf((actions.PosttestAction != null), "Executing post-test script...");
            ExecutionResult[] posttestResults = TestService.Execute(this.PrivilegedContext, this.PrivilegedContext, actions.PosttestAction);
        }

        #endregion

        #region private void InitializeComponent()

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            Microsoft.Data.Schema.UnitTesting.DatabaseTestAction SqlLogInsertStoredProcedureUnitTest_TestAction;
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SqlLogInsertUnitTest));
            Microsoft.Data.Schema.UnitTesting.DatabaseTestAction testInitializeAction;
            Microsoft.Data.Schema.UnitTesting.DatabaseTestAction testCleanupAction;
            this.SqlLogInsertStoredProcedureUnitTestData = new Microsoft.Data.Schema.UnitTesting.DatabaseTestActions();
            SqlLogInsertStoredProcedureUnitTest_TestAction = new Microsoft.Data.Schema.UnitTesting.DatabaseTestAction();
            testInitializeAction = new Microsoft.Data.Schema.UnitTesting.DatabaseTestAction();
            testCleanupAction = new Microsoft.Data.Schema.UnitTesting.DatabaseTestAction();
            // 
            // SqlLogInsertStoredProcedureUnitTest_TestAction
            // 
            resources.ApplyResources(SqlLogInsertStoredProcedureUnitTest_TestAction, "SqlLogInsertStoredProcedureUnitTest_TestAction");
            // 
            // testInitializeAction
            // 
            resources.ApplyResources(testInitializeAction, "testInitializeAction");
            // 
            // testCleanupAction
            // 
            resources.ApplyResources(testCleanupAction, "testCleanupAction");
            // 
            // SqlLogInsertStoredProcedureUnitTestData
            // 
            this.SqlLogInsertStoredProcedureUnitTestData.PosttestAction = null;
            this.SqlLogInsertStoredProcedureUnitTestData.PretestAction = null;
            this.SqlLogInsertStoredProcedureUnitTestData.TestAction = SqlLogInsertStoredProcedureUnitTest_TestAction;
            // 
            // SqlLogInsertUnitTest
            // 
            this.TestCleanupAction = testCleanupAction;
            this.TestInitializeAction = testInitializeAction;
        }

        #endregion
    }
}
